# $Id: probe.tcl 46 2007-09-09 16:46:20Z khomoutov $
# probe.tcl user@host[:port] ?options?

lappend auto_path [file join .. tcldc]

package require dcclient

proc usage {{chan stdout}} {
	puts $chan "Usage: [file tail [info script]] user@host\[:port\] ?options?"
}

namespace eval my {
	proc connected {sock connected error} {
		puts "connected: $sock; connected? $connected; $error"
		global forever
		set forever done
	}
}

global argc argv

if {$argc < 1} {
	usage stderr
	exit 1
}

lassign [split [lindex $argv 0] @] user hostspec
lassign [split $hostspec :] host port

if {$port == ""} { set port 411 }

if 0 {
	# sync:
	set sock [eval [list ::dccore::connect -host $host -port $port \
		-encoding [encoding system]] [lrange $argv 1 end]]
} else {
	# async:
	after 500 [list puts "async event..."]
	set sock [eval [list ::dccore::connect -host $host -port $port \
		-encoding [encoding system] -async ::my::connected] [lrange $argv 1 end]]
	vwait forever
}

puts "returned: $sock"


